/**
 * 
 */
package com.feib.stms.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import com.feib.stms.dao.SecuritiesDao;
import com.feib.stms.model.Securities;
import com.feib.stms.pagination.PaginatedList;
import com.feib.stms.service.SecuritiesService;

/**
 * @author Jimmy Liu
 *
 */
@Service("securitiesService")
public class SecuritiesServiceImpl extends BaseServiceImpl implements SecuritiesService 
{
	private static final long serialVersionUID = -4455956594413587545L;

	@Resource(name="securitiesDao")
    private SecuritiesDao securitiesDao;
	
	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#findForPaginatedListBySecurities(com.feib.stms.model.Securities)
	 */
	public PaginatedList<Securities> findForPaginatedListBySecurities(Securities securities, PaginatedList paginatedList) {
		return securitiesDao.findForPaginatedListBySecurities(securities, paginatedList);
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#saveSecurities(com.feib.stms.model.Securities)
	 */
	public int saveSecurities(Securities securities) {
		int insertCount = securitiesDao.insert(securities);
        return insertCount;		
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#updateSecurities(com.feib.stms.model.Securities)
	 */
	public int updateSecurities(Securities securities) {
		return securitiesDao.update(securities);
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#findParentSecuritiesPk(com.feib.stms.model.Securities)
	 */
	public long findParentSecuritiesPk(Long groupPk) {
		return securitiesDao.findParentSecuritiesPk(groupPk);
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#getBySecuritiesPk(com.feib.stms.model.Securities)
	 */
	public Securities getBySecuritiesPk(Long securitiesPk) {
		return securitiesDao.findSecuritiesBySecuritiesPk(securitiesPk);
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#findForSecuritiesListByGroupPks(com.feib.stms.model.Securities)
	 */
	public List<Securities> findForSecuritiesListByGroupPks(List<String> userGroupPk) {
		return securitiesDao.findSecuritiesByGroupPk(userGroupPk);
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#findForListBySecurities(com.feib.stms.model.Securities)
	 */
	public List<Securities> findForListBySecurities() {
		return securitiesDao.findAllSecurities();
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#findAll()
	 */
	public List<Securities> findAll() {
		return this.securitiesDao.loadAll();
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#findForSecuritiesListBySecuritiesNos(com.feib.stms.model.Securities)
	 */
	public List<Securities> findForSecuritiesListBySecuritiesNos(List<String> securitiesNo) {
		
		/*  在點選操作紀錄查詢的時候，當讀取不到使用者可查詢分公司時 應該不能顯示分公司 */
		
		if(CollectionUtils.isNotEmpty(securitiesNo)){
			return this.securitiesDao.findSecuritiesBySecuritiesNos(securitiesNo);
		}else{
			return new ArrayList<Securities>();
		}
		
		
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#countSecuritiesNo(java.lang.String)
	 */
	public int countSecuritiesNo(String securities_No) {
		return this.securitiesDao.countSecuritiesNo(securities_No);
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#findForSecuritiesBySecuritiesNoAndGroupPk(java.lang.String,java.lang.Long)
	 */
	public Securities findForSecuritiesBySecuritiesNoAndGroupPk(String securitiesNo, Long groupPk) {
		return this.securitiesDao.getBySecuritiesNoAndGroupPk(securitiesNo, groupPk);
	}

	/*
	 * (non-Javadoc)
	 * @see com.feib.stms.service.SecuritiesService#findForSecuritiesBySecuritiesNo(java.lang.String)
	 */
	public Securities findForSecuritiesBySecuritiesNo(String securitiesNo) {
		return this.securitiesDao.getBySecuritiesNo(securitiesNo);
	}

	public PaginatedList<Securities> findForPaginatedListNotBank(Securities securities, PaginatedList paginatedList) {
		
		return this.securitiesDao.findForPaginatedListNotBank(securities, paginatedList);
	}
	
}
